﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace B.S.BasicData.Api.Read.Filter
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class ExceptionFilter : IExceptionFilter
    {

        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ExceptionFilter> logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger">日志</param>
        public ExceptionFilter(ILogger<ExceptionFilter> logger)
        {
            this.logger = logger;
        }


        /// <summary>
        /// 当异常发生时
        /// </summary>
        /// <param name="context">异常记录</param>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("【全局异常过滤器】出错" + context.Exception.Message);

        }
    }
}
